// pages/ScenicArea/ScenicAreaCommitPage/index.js
var common = require("../../../public.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showBuyerPanel: false,
    storeInfo: {},
    ticketOrder: '',
    orderNo: '',
    isLoading: false,
    orderobj:"",
    ticketTime:''
  },

  onLoad: function (options) {
    const that = this
    console.log(options)
    wx.getStorage({
      key: 'user',
      success: function (res) {
        that.setData({
          userInfo: res.data.user,
          token: res.data.token,
          openid: res.data.openid,
          orderNo: options.orderNo,
          orderobj:options.obj,
          tiaoFlag:options.flag ? options.flag: ''
        }, () => {
          that.initData();
          console.log(that.data.orderobj,"555144555")
        })
      }
    })
  },
  initData() {
    const that = this
    let tempJson = {
      userId: that.data.userInfo.id,
      token: that.data.token,
      orderNo: that.data.orderNo,
    }
    this.setData({
      isLoading: true
    })
    common.post('/ticketOrder/getMyTicketOrderDetail', tempJson, function (res) {
      if (res.status === 200) {
        that.setData({
          scenicTicket:res.data.scenicTicket,
          storeInfo: res.data.store,
          ticketOrder: res.data.ticketOrder,
          ticketTime:res.data.ticketTime
        })
      } else {
        common.showRequestErrMsg(res)
      }
    }, function () {
      that.setData({
        isLoading: false
      })
    })
  },
  toEticket() {
    if (this.data.ticketOrder.status == 2 || this.data.ticketOrder.status == 5) {
       if(this.data.tiaoFlag==6){
        wx.navigateTo({
          url: '/pages/ScenicArea/CardETicket/index?orderNo=' + this.data.ticketOrder.orderNo,
        })
       }else{
        wx.navigateTo({
          url: '/pages/ScenicArea/ScenicAreaETicket/index?orderNo=' + this.data.ticketOrder.orderNo,
        })
       }
     
    } else {
      common.showToast('当前订单不可查看电子票')
    }
  },
  toStore() {
    const type = this.data.storeInfo.storeType == 6 ? 1 : 2
    wx.navigateTo({
      url: '/pages/ScenicArea/ScenicAreaMainPage/index?moduleType=' + type + '&id=' + this.data.storeInfo.id,
    })
  },
  makePhone() {
    wx.makePhoneCall({
      phoneNumber: this.data.storeInfo.mobile,
    })
  },
  goback() {
    wx.navigateBack({
      delta: 1,
    })
  },
  refund() {
    const that = this
    common.showAlertView('提示', '您确定要申请退款吗？申请退款后,1-7个工作日返回', function (sure) {
      if (sure) {
        const param = {
          orderNo: that.data.ticketOrder.orderNo,
          userId: that.data.userInfo.id,
          token: that.data.token,
        }
        common.post('/ticketOrder/refundTicketOrder', param, function (res) {
          if (res.status === 200) {
            const pages = getCurrentPages()
            const prePage = pages[pages.length - 2]
            wx.navigateBack({
              delta: 1,
              success: function () {
                common.showToast('退款成功')
                if (prePage && prePage.reloadData) {
                  prePage.reloadData()
                }
              }
            })
          } else {
            common.showRequestErrMsg(res)
          }
        })
      }
    })
  }
})